<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>选择区域</title>
<%@ include file="/WEB-INF/component/commonCSS.jsp"%>

<!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue sidebar-mini fixed skin-blue-light-frame">

	<section class="content">
		<div class=" box box-success">
		
		<div class="box-body">
                <div class="input">
            	
            	<div class="textalign"> 地市：</div>
                <div class="boxinput">
                     <select class="textinput" id="fatherCode"  name="fatherCode">
                            <option value="">请选择</option>
                            <c:forEach items="${countryList }" var="list">
                            	<option value="${list.area_id }">${list.area_name }</option>
                            </c:forEach>
                       </select>
                </div>
                 <div class="textalign">
                  		<button  id="selectSeesDel" type="button" onclick="gridSerch();" class="btn btn-success btn-sm">查 询</button>
                  </div>
            </div>
            
            </div>
		
		
		</div>


		<table class="jqgrid" id="gridlist"></table>
		<div id="gridpage"></div>
		<div class=" box box-warning bottongroup">
			<button type="button" onclick="areaSelect();" class="btn btn-primary btn-sm">选 择</button>
		</div>
	</section>
	<%@ include file="/WEB-INF/component/commonJS.jsp"%>
	<script type="text/javascript">
	
	//绑定回车   id="selectSee"
    $('#areaName').bind('keydown', function(event) {
        if (event.keyCode == "13") {
            $('#selectSee').click();
        }
    }); 
	
        $(function () {
             $("#gridlist").jqGrid({
                url: "${ctx}/baseDelAreaRel/getAreaListWithCity.html?compCode=${param.compCode}",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 185,
				shrinkToFit: true,
                colNames: ['地区编码','地市名称'],
                colModel: [
         			{ name: 'area_id', hidden:true,width: 150, align: "center", sortable:false },
                    { name: 'area_name', width: 200, align: "center", sortable:false }
                ],
                rowNum: 10,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "配送区域选择", 	
                jsonReader: {
                    repeatitems: false,
                    id: "ids"
                },
                gridComplete:function(){
					//序号列宽度自适应（参数为jqgridID）
					autoRNWidth("gridlist");
					//数据只有一条时默认选中（参数为jqgridID）
					selectByOneData("gridlist");
	                }
            }); 
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        
        function gridSerch() {
        	var fatherCode =  $.trim($("#fatherCode").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{
    	        		"fatherCode":fatherCode
						},
    	        		page:1
    	    }).trigger("reloadGrid"); //重新载入  
    	}
        
        function areaSelect(){
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
            	top.$.HN.message.alert("请选择区域！", "<spring:message code="message.HN.alert.type"/>", "warn");
                return;
            }
            var list = [];
            var areaIds = "";
            var areaNames = "";
            for (var i=0; i<rowIds.length; i++) {
                rowId = rowIds[i];
                var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
                areaIds += rowdata.area_id + ",";
                areaNames += rowdata.area_name + "; "
			}
            areaIds = areaIds.substr(0,areaIds.length - 1);
            areaNames = areaNames.substr(0, areaNames.length - 2);
        	 var dialog = top.dialog.get(window);
        	 dialog.close("${param.delId}|$${param.delTxt}|$"+areaIds+'|$'+areaNames); // 关闭（隐藏）对话框
        	 dialog.remove();				 // 主动销毁对话框
 			return false;
        }
       
    </script>
</body>
</html>